/*
 * TCSS 360 - Winter 2014
 * TESK Software
 */
package view;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JComboBox;
import javax.swing.JButton;

import view.Papers.SubmitReviewView;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.FlowLayout;

/**
 * Provides a conference selection for the reviewer.
 * 
 * @author Emily
 * @version March 20, 2014
 */
public class SelectConferenceReviewer extends JPanel {

	/** The frame the panel is associated with. */
	private MainFrame my_frame;

	/** The panel the frame was previously associated with. */
	private JPanel my_panel;

	/**
	 * Constructs the panel for the conference selection.
	 * 
	 * @param the_frame the frame to associate the panel with
	 * @param the_panel the panel that was previously associated with the frame
	 */
	public SelectConferenceReviewer(MainFrame the_frame, JPanel the_panel) {
		my_frame = the_frame;
		my_panel = the_panel;
		setBackground(new Color(240, 255, 255));
		setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JPanel basePanel = new JPanel();
		basePanel.setBackground(new Color(240, 255, 255));
		basePanel.setPreferredSize(new Dimension(490,490));
		add(basePanel);
		basePanel.setLayout(null);

		JLabel lblSelectAConference = new JLabel("Select a Conference: ");
		lblSelectAConference.setBounds(40, 114, 142, 42);
		basePanel.add(lblSelectAConference);
		lblSelectAConference.setFont(new Font("Urdu Typesetting", Font.PLAIN, 16));
		lblSelectAConference.setForeground(new Color(138, 43, 226));
		ArrayList<String> conferenceList = my_frame.db.getConferences();

		String[] conferenceArray = new String[conferenceList.size() + 1];
		conferenceArray[0] = null;
		for (int i = 0; i < conferenceList.size(); i++) {
			conferenceArray[i + 1] = conferenceList.get(i);
		}
		final JComboBox<String> conferenceComboBox = new JComboBox(conferenceArray);
		conferenceComboBox.setBounds(219, 119, 173, 37);
		basePanel.add(conferenceComboBox);

		JButton continueButton = new JButton("Continue");
		continueButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
		continueButton.setBounds(166, 201, 151, 29);
		basePanel.add(continueButton);
		continueButton.setForeground(new Color(0, 0, 255));

		JButton cancelButton = new JButton("Cancel");
		cancelButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
		cancelButton.setBounds(166, 242, 151, 29);
		basePanel.add(cancelButton);
		cancelButton.setForeground(new Color(0, 0, 255));

		//pictures
		JLabel lblChooseTheConference = new JLabel("Choose a conference you want to view and edit your reviews,");
		lblChooseTheConference.setFont(new Font("Tahoma", Font.ITALIC, 14));
		lblChooseTheConference.setBounds(23, 11, 426, 37);
		basePanel.add(lblChooseTheConference);

		JLabel lblAndEditYour = new JLabel(" then click Continue or go back to your main page.");
		lblAndEditYour.setFont(new Font("Tahoma", Font.ITALIC, 14));
		lblAndEditYour.setBounds(23, 46, 357, 37);
		basePanel.add(lblAndEditYour);


		ImageIcon icon = new ImageIcon(getClass().getResource("/tree.jpg"));

		final JLabel pic = new JLabel();
		pic.setBounds(0, 300, 500, 200);
		basePanel.add(pic);
		pic.setIcon(icon);


		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				my_frame.setNewPanel(my_panel);
				my_frame.repaint();
			}
		});
		continueButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (conferenceComboBox.getSelectedItem() != null) {
					my_frame.setNewPanel(new SubmitReviewView(my_frame, (String)conferenceComboBox.getSelectedItem()));
				} else {
					JOptionPane.showMessageDialog(my_frame,  "Please select a conference!", "Error!", JOptionPane.ERROR_MESSAGE);
				}
			}
		});


	}
}
